import request from '@/utils/request'

// 生成合同
export function generateContract(data) {
  return request({
    url: '/audit/contract/generate',
    method: 'post',
    data: data
  })
}

// 下载合同
export function downloadContract(contractNo) {
  return request({
    url: `/audit/contract/download/${contractNo}`,
    method: 'get',
    responseType: 'blob'
  })
}

// 获取合同历史 (按结构ID)
export function getContractHistory(structId) {
  return request({
    url: `/audit/contract/struct/${structId}`,
    method: 'get'
  })
}

// 获取合同链上状态
export function getContractChainStatus(contractNo) {
  return request({
    url: `/audit/contract/chainStatus/${contractNo}`,
    method: 'get'
  })
}

// 验证合同链上信息
export function verifyContractChainData(contractNo) {
  return request({
    url: `/audit/contract/verifyChain/${contractNo}`,
    method: 'get'
  })
}

// 上传文件验证合同
export function verifyContractByUpload(data) {
  return request({
    url: '/audit/contract/verifyUpload',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 手动将合同上链
export function uploadContractToChain(contractNo) {
  return request({
    url: `/audit/contract/uploadToChain/${contractNo}`,
    method: 'post'
  })
}

// 查询合同记录列表
export function listContract(query) {
  return request({
    url: '/audit/contract/list',
    method: 'get',
    params: query
  })
}

// 查询合同记录详细
export function getContract(id) {
  return request({
    url: '/audit/contract/' + id,
    method: 'get'
  })
}

// 删除合同记录
export function delContract(id) {
  return request({
    url: '/audit/contract/remove/' + id,
    method: 'get'
  })
}

// 导出合同记录
export function exportContract(query) {
  return request({
    url: '/audit/contract/export',
    method: 'get',
    params: query
  })
}

// 更新合同状态
export function updateContractStatus(data) {
  return request({
    url: '/audit/contract/updateStatus',
    method: 'post',
    data: data
  })
}

// 获取合同模板列表
export function listContractTemplates() {
  return request({
    url: '/audit/contract/templates',
    method: 'get'
  })
}

// 替换合同文件
export function replaceContract(data) {
  return request({
    url: '/audit/contract/replace',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
